import { http } from './axios'

const MessageUserRecords = {

    /**
     * 消息拉取
     * @param {*} sessionId 会话id
     * @param {*} messageId 最后一条消息id
     * @returns 
     */
    list: function (sessionId, messageId) {
        return http.get('/modular/message-user-records/list/' + sessionId, {
            params: {
                messageId: messageId
            }
        });
    },

    /**
     * 创建消息
     * @param {*} sessionId 会话id
     * @param {*} contentType 消息类型
     * @param {*} content 消息体
     * @returns 
     */
    createMessage: function (sessionId, contentType, content) {
        return http.post('/modular/message-user-records/createMessage', {
            sessionId: sessionId,
            contentType: contentType,
            content: content
        });
    },

    /**
     * 发送消息
     * @param {*} sessionId 会话id
     * @param {*} messageId 消息id
     * @returns 
     */
    sendMessage: function (sessionId, messageId) {
        return http.post('/modular/message-user-records/sendMessage', {
            sessionId: sessionId,
            messageId: messageId
        });
    }
}


const ChatSession = {

    /**
     * 查询会话
     * @param {*} sessionId 会话id
     * @returns 
     */
    get: function (sessionId) {
        return http.get('/modular/chat-session/get/' + sessionId);
    },
    /**
     * 消息已读
     * @param {*} sessionId 会话id
     * @returns 
     */
    readCount: function (sessionId) {
        return http.post('/modular/chat-session/readCount/' + sessionId);
    }
}

const UserFriend = {

    /**
     * 列表
     * @param {*} data 查询条件
     * @returns 
     */
    list: function (data) {
        return http.post('/modular/user-friend/list', data ? data : {});
    },

    /**
     * 新增好友
     * @param {*} friendUserId 好友id
     * @returns 
     */
    add: function (friendUserId) {
        return http.post('/modular/user-friend/add/' + friendUserId);
    },
    /**
     * 删除好友
     * @param {*} friendUserId 好友id
     * @returns 
     */
    del: function (friendUserId) {
        return http.post('/modular/user-friend/delFriend/' + friendUserId);
    },
    /**
     * 好友查询
     * @param {*} userId 好友id
     * @returns 
     */
    getFriend: function (userId) {
        return http.get('/modular/user-friend/getFriend/' + userId);
    }
}


const User = {

    list: function (data) {
        return http.post('/modular/user/list', data ? data : {});
    }
}

export { MessageUserRecords, ChatSession, UserFriend, User };